package com.framework.Module.system.option;

import com.framework.Table.Table;
import com.framerock.baselib.Rock;
import com.framework.ACore.Model;

import java.util.ArrayList;
import java.util.Map;

public class Tableoption extends  Table{
   
    protected void initTable() {
        this.tablename   = "option";
        this.tablenamesm = "数据选项";

        this.flowsetMap  = Rock.getMap(new String[]{
                "type", "系统",
                "sort", "905",
                "isxt", "1",
        });

        this.addfields("name", "varchar(100)", "", "名称",new String[]{
                "iseditlx","1",
                "isalign","1"
        });
        this.addfields("num", "varchar(50)", "", "编号",new String[]{
                "iseditlx","0",
                "attr","onlyen",
                "isonly", "1"
        });
        this.addfields("value", "varchar(2000)", "", "对应值",new String[]{
                "iseditlx","1",
                "isalign","1"
        });
        this.addfields("pid", "int(11)", "0", "上级ID");
        this.addfields("optdt", "datetime", null, "操作时间",new String[]{
                "islu","0",
                "islb" , "0"
        });
        this.addfields("valid", "tinyint(1)", "1", "有效",new String[]{
                "iseditlx","1",
                "ispx" , "1"
        });
        this.addfields("sort", "int(11)", "0", "排序",new String[]{
                "iseditlx","1",
                "ispx" , "1"
        });
        this.addfields("temp_down", "int(11)", "0", "下级数",new String[]{
                "islu","0"
        });
        this.addfields("explain", "varchar(100)", "", "说明");
        this.addfields("id", "int(11)", "0", "ID");
        this.addfields("num", "KEY", "`num`", "编号索引");
        this.addfields("pid", "KEY", "`pid`", "PID索引");
    }

    protected void firstInsert() {
        ArrayList<Map<String, String>> rows = new ArrayList<Map<String, String>>();
        rows.add(Rock.getMap("id=1,num=xinhu,name=选项,sort=0,pid=0"));

        rows.add(Rock.getMap("num=platcog,name=平台选项,sort=0,pnum=xinhu"));
        rows.add(Rock.getMap("num=rockfile,name=上传文件中心,sort=1,pnum=xinhu"));
        rows.add(Rock.getMap("num=service,name=通信服务端,sort=2,pnum=xinhu"));

        rows.add(Rock.getMap("pnum=platcog,num=systemtitle,name=系统标题,value=信呼Java云平台,sort=0"));
        rows.add(Rock.getMap("pnum=platcog,num=fieldstype,name=字段类型,sort=1"));
        rows.add(Rock.getMap("pnum=platcog,num=flowmenutype,name=单据操作菜单类型,sort=2"));
        rows.add(Rock.getMap("pnum=platcog,num=mtypeicon,name=模块类型,sort=3,explain=展开对应值设置图标"));
        rows.add(Rock.getMap("pnum=platcog,num=checktype,name=审核步骤类型,sort=4"));
        rows.add(Rock.getMap("pnum=platcog,num=findcode,name=找回密码手机验证码,sort=5,explain=对应值设置1就需要"));
        rows.add(Rock.getMap("pnum=platcog,num=smscog,name=短信设置,sort=6"));
        rows.add(Rock.getMap("pnum=platcog,num=tasklast,name=计划任务最后运行,sort=7"));

        rows.add(Rock.getMap("pnum=smscog,num=smstype,name=短信平台,sort=0,explain=可设置xinhu|yunpian|aliyun"));
        rows.add(Rock.getMap("pnum=smscog,num=smsqianm,name=短信签名,sort=1"));

        rows.add(Rock.getMap("pnum=rockfile,num=rockfile_url,name=上传文件中心地址,sort=0"));
        rows.add(Rock.getMap("pnum=rockfile,num=rockfile_key,name=上传文件中心Key,sort=1"));

        rows.add(Rock.getMap("pnum=service,num=service_url,name=通信地址,sort=0"));
        rows.add(Rock.getMap("pnum=service,num=service_push,name=推送地址,sort=1"));
        rows.add(Rock.getMap("pnum=service,num=service_recid,name=recID,sort=2"));
        rows.add(Rock.getMap("pnum=service,num=service_cehui,name=撤回时间(分钟),value=2,sort=3,explain=0不能撤回"));


        Map<String, String> da,rs,pnumarr = Rock.getMap();
        storeList = Rock.getMapList();
        adddList("text", "文本框");
        adddList("date", "日期");
        adddList("datetime", "日期时间");
        adddList("hidden", "隐藏文本框");
        adddList("number", "数字");
        adddList("textarea", "文本域");
        adddList("select", "下拉框");
        adddList("changeuser", "选择人员(单选)");
        adddList("changeusercheck", "选择人员(多选)");
        adddList("changedept", "选择部门");
        adddList("changedeptcheck", "选择部门(多选)");
        adddList("changedeptusercheck", "选择部门人员组");
        adddList("rockcombo", "数据选项下拉框");
        adddList("htmlediter", "html编辑器");
        adddList("checkbox", "单个复选框");
        adddList("checkboxall", "多个复选框");
        adddList("month", "月份");
        adddList("uploadimg", "单图片上传");
        adddList("uploadfile", "文件上传(可多选)");
        adddList("num", "自动编号");
        adddList("selectdatafalse", "弹框下拉选择(单选)");
        adddList("selectdatatrue", "弹框下拉选择(多选)");
        adddList("radio", "单选框");
        adddList("subdata", "子表", "数据源写模块编号");
        adddList("auto", "自定义", "写模块js文件里");

        for(int i=0;i<storeList.size();i++){
            da = storeList.get(i);
            da.put("sort", i+"");
            da.put("pnum", "fieldstype");
            rows.add(da);
        }

        storeList = Rock.getMapList();
        adddList("super", "直属上级");
        adddList("user", "指定人员");
        adddList("dept", "部门负责人");
        adddList("rank", "指定职位");
        adddList("apply", "申请人");
        adddList("auto", "自定义(写代码上)");
        for(int i=0;i<storeList.size();i++){
            da = storeList.get(i);
            da.put("sort", i+"");
            da.put("pnum", "checktype");
            rows.add(da);
        }

        storeList = Rock.getMapList();
        adddList("0", "直接操作");
        adddList("1", "弹出填写说明");
        adddList("2", "人员选择(单人)");
        adddList("3", "人员选择(多人)");
        adddList("6", "人员选择(多选部门人员组)");
        adddList("4", "更新字段");
        adddList("5", "打开新窗口");
        adddList("7", "自定义方法(需开发)","写模块js里面");
        for(int i=0;i<storeList.size();i++){
            da = storeList.get(i);
            da.put("sort", i+"");
            da.put("pnum", "flowmenutype");
            rows.add(da);
        }

        storeList = Rock.getMapList();
        adddList("check-empty", "基础");
        adddList("retweet", "流程");
        adddList("beer", "行政");
        adddList("truck", "进销存");
        adddList("asterisk", "系统");
        adddList("user", "人事");
        adddList("hand-up", "考勤");
        for(int i=0;i<storeList.size();i++){
            da = storeList.get(i);
            da.put("sort", i+"");
            da.put("pnum", "mtypeicon");
            rows.add(da);
        }


        Model obj = Model.get(this.nDb, this.tablename);
        String where = "",pid,pnum,id;
        for(int i=0;i<rows.size();i++){
            da  = rows.get(i);
            pid = da.get("pid");
            pnum= da.get("pnum");
            id  = da.get("id");

            if(!Rock.isEmpt(pnum)) {
                pid = Rock.getMapString(pnumarr, pnum, "");
                if(Rock.isEmpt(pid)){
                    rs = obj.getOne("`num`='"+pnum+"'");
                    if(rs!=null){
                        pid = rs.get("id");
                        pnumarr.put(pnum, pid);
                    }
                }
                da.put("pid", pid);
                da.remove("pnum");
            }
            if(Rock.isEmpt(pid))continue;

            where = "`pid`="+pid+" and `name`='"+da.get("name")+"'";
            if(obj.getCount(where)==0) {
                obj.insertbo(da);
            }else{
                 //da.remove("id");
                 //obj.update(da, where);
            }
        }

    }

    protected ArrayList<Map<String, String>> storeList = null;
    protected void adddList(String value, String name){
        adddList(value, name, "");
    }
    protected void adddList(String value, String name, String sm){
        if(storeList==null)storeList = new ArrayList<Map<String, String>>();
        storeList.add(Rock.getMap(new String[]{"value",value, "name", name, "explain", sm}));
    }
}
